import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'logic.dart';

class AddTemplatePage extends StatelessWidget {
  const AddTemplatePage({super.key});

  @override
  Widget build(BuildContext context) {
    final AddTemplateLogic logic = Get.find<AddTemplateLogic>();
    final state = logic.state;
    return Scaffold(
        appBar: AppBar(title: Text(logic.bean.isAdd ? "添加任务模版" : "修改任务模版")),
        body: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Column(children: [
              TextField(
                  controller: logic.descController,
                  decoration: const InputDecoration(
                      hintText: "请输入模版描述",
                      isDense: true,
                      isCollapsed: true,
                      contentPadding: EdgeInsets.all(5)),
                  maxLines: null),
              const SizedBox(height: 10),
              Row(
                children: [
                  Expanded(child: Obx(() {
                    if (state.selectedConfig.value == null) {
                      return const Text("未选择");
                    } else {
                      return Text(
                          "所选配置：${state.selectedConfig.value?.description}");
                    }
                  })),
                  ElevatedButton(
                      onPressed: logic.selectConfig,
                      child: const Text("选择配置文件"))
                ],
              ),
              const SizedBox(height: 10),
              Row(
                children: [
                  Expanded(child: Obx(() {
                    if (state.flow.value == null) {
                      return const Text("未选择");
                    }
                    return Text("流程：${state.flow.value?.step}");
                  })),
                  ElevatedButton(
                      onPressed: logic.selectFlow, child: const Text("选择流程"))
                ],
              ),
              const SizedBox(height: 10),
              ElevatedButton(
                  onPressed: logic.addTaskTemplate,
                  child: Center(child: Text(logic.bean.isAdd ? "添加" : "修改")))
            ])));
  }
}
